/*
 * Copyright (c) 2015 YCY Group Holding Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *
 * $Id: UserUitls.java  2015-8-6 上午11:47:03 jackLiang $
 */
package com.jkwzms.system.utils;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.realm.UserRealm.Principal;

import com.alibaba.fastjson.JSON;
import com.jkwzms.common.utils.SpringUtils;
import com.jkwzms.system.user.entity.User;
import com.jkwzms.system.user.service.UserService;

/**
 * 获取当前用户信息
 * 
 * @author JackLiang
 * @date 2015-8-6
 * @version 1.0.0
 */
public final class UserUitls {

    private static UserService userService = SpringUtils.getBean(UserService.class);

    /**
     * 获取用户对象
     * 
     * @return
     */
    public static User getCurrentUser() {
        User user = null;
        Principal principal = (Principal) SecurityUtils.getSubject().getPrincipal();
        if (null != principal) {
            user = userService.findByUsername(principal.getLoginName());
        }
        return user;
    }

    /**
     * 获取当前用户登录ID
     * 
     * @return
     */
    public static String getCurrentUsername() {
        Principal principal = (Principal) SecurityUtils.getSubject().getPrincipal();
        return principal == null ? "" : principal.getLoginName();
    }

    /**
     * 获取当前用户的真实姓名
     * 
     * @return
     */
    public static String getCurrentFullName() {
        Principal principal = (Principal) SecurityUtils.getSubject().getPrincipal();
        return principal == null ? "" : principal.getName();
    }

}
